package logic

import (
	"context"
	"fmt"
	"srv/model/mysql"

	"srv/internal/svc"
	"srv/srv"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodInfoLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodInfoLogic {
	return &GoodInfoLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodInfoLogic) GoodInfo(in *srv.GoodInfoRequest) (*srv.GoodInfoResponse, error) {
	// todo: add your logic here and delete this line

	g := mysql.Good{}
	err := g.GoodInfo(int(in.Id))
	if err != nil {
		return nil, fmt.Errorf("商品不存在")
	}

	return &srv.GoodInfoResponse{
		GoodId:    int64(g.ID),
		GoodName:  g.GoodName,
		GoodNum:   g.GoodNum,
		GoodPrice: float32(g.GoodPrice),
		GoodLike:  g.GoodLike,
	}, nil
}
